﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PurchasePaymentListCtrl.ascx.cs"
    Inherits="WebUI.Controls.PurchasePaymentListCtrl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<script type="text/javascript">
var <%=ClientID %>clickOnCheckbox;
var <%=ClientID %>selectedRow = null;       
var <%=ClientID %>selectedCheckbox = null; 
var <%=ClientID %>selectedID = null; 
var <%=ClientID %>selectedClass = null; 

function resetGridSelection<%=ClientID %>(){
    <%=ClientID %>selectedRow = null;   
    if(<%=ClientID %>selectedCheckbox != null)
        <%=ClientID %>selectedCheckbox.checked = false;          
    <%=ClientID %>selectedCheckbox = null; 
    <%=ClientID %>selectedID = null; 
    <%=ClientID %>selectedClass = null; 
}

function clickOnCheckBox<%=ClientID %>(cb){
    <%=ClientID %>clickOnCheckbox = true;
}

function onItemClick<%=ClientID %>(sender)
{
    if(<%=ClientID %>clickOnCheckbox){
        <%=ClientID %>clickOnCheckbox = false;
        return;
    }
    
    if(<%=ClientID %>selectedRow != null){
        if(<%=ClientID %>selectedRow.className)
            <%=ClientID %>selectedRow.className = <%=ClientID %>selectedClass;
        else
            <%=ClientID %>selectedRow.setAttribute("class", <%=ClientID %>selectedClass);
        if(<%=ClientID %>selectedCheckbox != null)
            <%=ClientID %>selectedCheckbox.checked = false;
    }
    
    if(sender.className){
        <%=ClientID %>selectedClass = sender.className;
        sender.className = "CustomGridSelectedItem";
    }
    else{
        <%=ClientID %>selectedClass = sender.getAttribute("class");
        sender.setAttribute("class", "CustomGridSelectedItem");
    }
    <%=ClientID %>selectedRow = sender;
    
    var inputs = sender.getElementsByTagName("input");
    for(var i = 0; i < inputs.length; i++){
        if(inputs[i].type == "checkbox" && inputs[i].id.indexOf("cbSelect") >= 0){
            <%=ClientID %>selectedCheckbox = inputs[i];
            inputs[i].checked = true;
            break;
        }
    }
    
    <%=ClientID %>selectedID = <%=ClientID %>selectedRow.getAttribute("ItemID");
}

function selectAll<%=ClientID %>(cbAll){
    var grid = document.getElementById("<%=grid.ClientID %>");
    var inputs = grid.getElementsByTagName("input");
    for(var i = 0; i < inputs.length; i++){
        if(inputs[i].type == "checkbox"){
            inputs[i].checked = cbAll.checked;
        }
    }
}

function getSelectedItemID<%=ClientID %>()
{
    return <%=ClientID %>selectedID;
}

</script>
<%--start modify here--%>
<table cellpadding="0" cellspacing="0">
    <tr>
        <td style="text-align: left; vertical-align: top" class='toolbar'>
            <asp:Label ID="lblTitle" runat="server" class='labelMessage0'></asp:Label>
        </td>
    </tr>
    <tr>
        <td style="text-align: left; vertical-align: top">
            <asp:DataGrid ID="grid" runat="server" AllowPaging="true" AllowSorting="true" GridLines="None"
                class="customGrid" ShowFooter="true" AutoGenerateColumns="false" EmptyDataText="No record to display"
                ItemStyle-Wrap="true" CellPadding="1" CellSpacing="1" OnSortCommand="grid_OnSortCommand"
                OnItemCreated="grid_OnItemCreated" OnItemDataBound="grid_OnItemDataBound" OnPageIndexChanged="grid_OnPageIndexChanged"
                AllowCustomPaging="true" UseAccessibleHeader="true" DataKeyField="ID">
                <PagerStyle Mode="NumericPages" PageButtonCount="10" />
                <Columns>
                    <asp:TemplateColumn ItemStyle-Width="20px" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center"
                        HeaderStyle-HorizontalAlign="Center">
                        <HeaderTemplate>
                            <asp:CheckBox ID="cbSelectAll" runat="server" /></HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="cbSelect" runat="server" ItemID='<%# Eval("ID") %>' />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <%--start modify here--%>
                    <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
                        ItemStyle-Width="150px" DataField="ID" SortExpression="ID" HeaderText="ID" Visible="false">
                    </asp:BoundColumn>
                    <asp:TemplateColumn HeaderText="Purchase#" ItemStyle-Width="100px" HeaderStyle-Width="200px"
                        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                        <ItemTemplate>
                            <asp:Label ID="lblPurchaseOrderNo" runat="server" Text='<%# Eval("PurchaseOrderNo") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Invoice#" ItemStyle-Width="100px" HeaderStyle-Width="200px"
                        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                        <ItemTemplate>
                            <asp:Label ID="lblInvoiceNo" runat="server" Text='<%# Eval("InvoiceNo") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Total Amount" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Right"
                        HeaderStyle-HorizontalAlign="Left">
                        <ItemTemplate>
                            <asp:Label ID="lblTotalAmt" runat="server" Text='<%# Eval("TotalAmount") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Paid Amount" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Right"
                        HeaderStyle-HorizontalAlign="Left">
                        <ItemTemplate>
                            <asp:Label ID="lblPaidAmt" runat="server" Text='<%# Eval("PaidAmount") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Balance" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Right"
                        HeaderStyle-HorizontalAlign="Left">
                        <ItemTemplate>
                            <asp:Label ID="lblBalance" runat="server" Text='<%# decimal.Parse(Eval("TotalAmount").ToString()) - decimal.Parse(Eval("PaidAmount").ToString()) %>'></asp:Label>
                            <asp:TextBox ID="txtBalance" Width="60px" runat="server" Text='<%# Eval("Balance").ToString() %>'></asp:TextBox>
                            <cc1:FilteredTextBoxExtender FilterType="Numbers, Custom" ValidChars="." TargetControlID="txtBalance"
                                ID="FilteredTextBoxExtenderSpecialPrice" runat="server">
                            </cc1:FilteredTextBoxExtender>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>
        </td>
    </tr>
</table>
<asp:HiddenField ID="hidSelectedID" runat="server" />